from . import user_bp
from flask import request
from flask_restful import Resource,Api
from model.userdb import User
from lib.response import response
from forms.user import UserForm

api = Api(user_bp)

class UserRegister(Resource):
    def post(self):
        data = request.json
        form = UserForm(data = data)
        if form.validate():
            User.create_user(data.get("username"),
                             form.password.data)
            return response(message="注册成功")
        else:
            return response(message=form.errors, code = 101)
api.add_resource(UserRegister,"/user")

